home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / misc / amag / AM95022.lha / c++-kurs-2 / Listing3.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-29  |  759 b   |  39 lines

  1. /* Listing3: © Clemens Marschner, 1994
  2.  * demonstriert die Verwendung von Mehrfachvererbung */
  3.  
  4. #include <stream.h>
  5.     
  6. class real {
  7.     float wert;
  8. public:
  9.     real(float w) : wert(w) {}
  10.     float read() { return wert; }
  11.     void write(float w) { wert=w; }
  12. };
  13.  
  14. class imag {
  15.     float wert;
  16. public:
  17.     imag(float w) : wert(w) {}
  18.     float read() { return wert; }
  19.     void write(float w) { wert=w; }
  20. };
  21.  
  22. class complex : public real, imag {
  23. public:
  24.     complex(float r, float i) : real(r), imag(i) {}
  25.     void print();
  26. };
  27.  
  28. void complex::print() {
  29.     cout << "(" << real::read() << "," << imag::read() << ")\n";
  30.     // Mehrdeutigkeiten -> Scope-Resolution Operator "::"
  31. }
  32.  
  33. void main() {
  34.     complex a(10,1.6);
  35.     cout << "Komplexe Zahl: ";
  36.     a.print();
  37. }
  38.  
  39.